<?php 
/**
* @package DomDB.Test
* @author Oliver Leisalu
*/
final class DomDBTestCases {

	public function basic_1() {
		$result = array();
		
		$a = new DomDBTestSimpleObject('a');

		$a->save();	
		
		$result[] = DomDBTester::testValue( 1, $a->id, 'name', 'a');

		$a->destroy();
		$la = DomDB::load( $a->id );
		$a->name = 'TEST';
		
		if( $a->name == $la->name )
			$result[] = array(false, 0,'DomDBObject->destroy is not working as expected!');
		
		$la->name = 'aa';
		$la->save('name');
		$result[] = DomDBTester::testValue( 1, $a->id, 'name', 'aa');
		
		$la->name = 'aaa';
		$la->save();
		$result[] = DomDBTester::testValue( 1, $a->id, 'name', 'aaa');

		$a->delete();
		
		$result[] = DomDBTester::testExistance( 2, $a->id, 'domdbtestsimpleobject');

		return $result;
	}
	
	
	public function tLoad_1() {
		$result = array();
		
		$a = new DomDBTestSimpleObject('a');
		$b = new DomDBTestSimpleObject('b');
		$c = new DomDBTestSimpleObject('c');

		$a->object = $b;
		$b->object = $c;
		$a->save();	
		
		$result[0] = DomDBTester::testValue( 1, $a->id, 'name', 'a');
		$result[1] = DomDBTester::testValue( 1, $b->id, 'name', 'b');
		$result[2] = DomDBTester::testValue( 1, $c->id, 'name', 'c');
		$result[3] = DomDBTester::testParent( 1, $a->id, 'object', $b->id);
		$result[4] = DomDBTester::testParent( 1, $b->id, 'object', $c->id);

		$a->destroy();
		$b->destroy();
		$c->destroy();
		
		$t = DomDB::tLoad( $a->id, 'DomDBTestSimpleObject' );
		if( !$t )
			$result['tload1'] = array(false, 0, 'Failed to load object');
		else
			$t->destroy();
		
	
		$p = DomDB::load( $a->id );
		$t = DomDB::tLoad( $b->id, 'DomDBTestSimpleObject', $p );
		if( !$t ) {
			$p->destroy();
			$result['tload2'] = array(false, 0, 'Failed to load object');
		} else {
			$t->destroy();
			$p->destroy();
		}
		
		
		$p = DomDB::load( $a->id );
		$t = DomDB::tLoad( $c->id, 'DomDBTestSimpleObject', $p );
		if( $t ) {
			$result['tload3'] = array(false, 0, 'Loaded object, but expected to fail!');
			$t->destroy();
			$p->destroy();
		} else {
			$p->destroy();
		}
		
		$p = DomDB::load( $a->id );
		$t = DomDB::tLoad( $c->id, 'DomDBTestSimpleObject', 'parent+', $p );
		if( !$t ) {
			$p->destroy();
			$result['tload4'] = array(false, 0, 'Failed to load object');
		} else {
			$t->destroy();
			$p->destroy();
		}
		
		$a->delete();
		
		$result[5] = DomDBTester::testExistance( 2, $a->id, 'domdbtestsimpleobject');
		$result[6] = DomDBTester::testExistance( 2, $b->id, 'domdbtestsimpleobject');


		return $result;
	}
	
	
	public function access_1() {
		$result = array();
		
		$a = new DomDBTestAccessObject('a');
		$a->init();
		$a->save();	
		
		$result[0] = DomDBTester::testValue( 1, $a->id, 'pro', 'pro');
		$result[1] = DomDBTester::testValue( 1, $a->id, 'proMet', 'proMet');
		$result[2] = DomDBTester::testValue( 1, $a->id, 'pri', '');
		$result[3] = DomDBTester::testValue( 1, $a->id, 'priMet', 'getPriMet_priMet');
		
		$a->pro = 'newPro';
		$result[4] = DomDBTester::testPair( 1, $a->pro, 'newPro');
		
		$a->proMet = 'newProMet';
		$result[5] = DomDBTester::testPair( 1, $a->proMet, 'getProMet_setProMet_newProMet');
		
		$a->pri = 'newPri';
		$result[6] = DomDBTester::testPair( 1, $a->pri, '');
		
		$a->priMet = 'newPriMet';
		$result[7] = DomDBTester::testPair( 1, $a->priMet, 'getPriMet_setPriMet_newPriMet');

		$a->delete();
		
		$result[8] = DomDBTester::testExistance( 2, $a->id, 'domdbtestsimpleobject');
		
		return $result;
	}
	
	
	public function oneToOne_1() {
		$result = array();
		
		$a = new DomDBTestSimpleObject('a');
		$b = new DomDBTestSimpleObject('b');
		$c = new DomDBTestSimpleObject('c');
		
		$a->object = $b;
		$b->object = $c;
		$a->save();	
		
		$result[] = DomDBTester::testValue( 1, $a->id, 'name', 'a');
		$result[] = DomDBTester::testValue( 1, $b->id, 'name', 'b');
		$result[] = DomDBTester::testValue( 1, $c->id, 'name', 'c');
		
		$result[] = DomDBTester::testParent( 1, $a->id, 'object', $b->id);
		$result[] = DomDBTester::testParent( 1, $b->id, 'object', $c->id);
		
		$a->delete();
		
		$result[] = DomDBTester::testExistance( 2, $a->id, 'domdbtestsimpleobject');
		$result[] = DomDBTester::testExistance( 2, $b->id, 'domdbtestsimpleobject');
		$result[] = DomDBTester::testExistance( 2, $c->id, 'domdbtestsimpleobject');

		return $result;
	}
	
	public function oneToOne_2() {
		$result = array();
		
		$a = new DomDBTestSimpleObject('a');
		$b = new DomDBTestSimpleObject('b');
		$c = new DomDBTestSimpleObject('c');
		
		$a->object = $b;
		$a->save();
		
		$result[] = DomDBTester::testValue( 1, $a->id, 'name', 'a');
		$result[] = DomDBTester::testValue( 1, $b->id, 'name', 'b');
		$result[] = DomDBTester::testParent( 1, $a->id, 'object', $b->id);
		
		$a->object = $c;
		
		$result[] = DomDBTester::testExistance( 2, $b->id, 'domdbtestsimpleobject');
		
		$a->save();	
		
		$result[] = DomDBTester::testValue( 1, $a->id, 'name', 'a');
		$result[] = DomDBTester::testValue( 1, $c->id, 'name', 'c');
		$result[] = DomDBTester::testParent( 1, $a->id, 'object', $c->id);
		
		$a->delete();
		
		$result[] = DomDBTester::testExistance( 2, $a->id, 'domdbtestsimpleobject');
		$result[] = DomDBTester::testExistance( 2, $c->id, 'domdbtestsimpleobject');

		return $result;
	}
	
	public function oneToOne_3() {
		$result = array();
		
		$a = new DomDBTestSimpleObject('a');
		$b = new DomDBTestSimpleObject('b');
		$c = new DomDBTestSimpleObject('c');
		
		$a->object = $b;
		$a->save();
		
		$result[0] = DomDBTester::testValue( 1, $a->id, 'name', 'a');
		$result[1] = DomDBTester::testValue( 1, $b->id, 'name', 'b');
		$result[2] = DomDBTester::testParent( 1, $a->id, 'object', $b->id);
		
		$b->object = $c;
		$b->save();	
		
		$result[3] = DomDBTester::testValue( 1, $b->id, 'name', 'b');
		$result[4] = DomDBTester::testValue( 1, $c->id, 'name', 'c');
		$result[5] = DomDBTester::testParent( 1, $b->id, 'object', $c->id);
		
		$a->delete();
		
		$result[6] = DomDBTester::testExistance( 2, $a->id, 'domdbtestsimpleobject');
		$result[7] = DomDBTester::testExistance( 2, $b->id, 'domdbtestsimpleobject');
		$result[8] = DomDBTester::testExistance( 2, $c->id, 'domdbtestsimpleobject');

		return $result;
	}
	
	public function oneToOne_4() {
		$result = array();
		
		$a = new DomDBTestSimpleObject('a');
		$b = new DomDBTestSimpleObject('b');

		$a->object = $b;
		$a->save();	
		
		$result[] = DomDBTester::testValue( 1, $a->id, 'name', 'a');
		$result[] = DomDBTester::testValue( 1, $b->id, 'name', 'b');
		$result[] = DomDBTester::testParent( 1, $a->id, 'object', $b->id);
		
		$b->removeParent();
		
		$result[] = DomDBTester::testValue( 1, $a->id, 'name', 'a');
		$result[] = DomDBTester::testValue( 1, $b->id, 'name', 'b');
		$result[] = DomDBTester::testParent( 2, $a->id, 'object', $b->id);
	
		$a->delete();
		$result[] = DomDBTester::testExistance( 2, $a->id, 'domdbtestsimpleobject');
		
		$b->delete();
		$result[] = DomDBTester::testExistance( 2, $b->id, 'domdbtestsimpleobject');

		return $result;
	}
	
	public function oneToOne_5() {
		$result = array();
		
		$a = new DomDBTestSimpleObject('a');
		$b = new DomDBTestSimpleObject('b');
		$c = new DomDBTestSimpleObject('c');
		
		$a->link = $c;
		$b->link = $c;
		
		$a->object = $b;
		$b->object = $c;
		
		$a->save();	
		
		$result[] = DomDBTester::testValue( 1, $a->id, 'name', 'a');
		$result[] = DomDBTester::testValue( 1, $b->id, 'name', 'b');
		$result[] = DomDBTester::testValue( 1, $c->id, 'name', 'c');
		$result[] = DomDBTester::testValue( 1, $a->id, 'link', $c->id);
		$result[] = DomDBTester::testValue( 1, $b->id, 'link', $c->id);
		$result[] = DomDBTester::testParent( 1, $a->id, 'object', $b->id);
		$result[] = DomDBTester::testParent( 1, $b->id, 'object', $c->id);
		
		$a->delete();
		
		$result[] = DomDBTester::testExistance( 2, $a->id, 'domdbtestsimpleobject');
		$result[] = DomDBTester::testExistance( 2, $b->id, 'domdbtestsimpleobject');
		$result[] = DomDBTester::testExistance( 2, $c->id, 'domdbtestsimpleobject');

		return $result;
	}
	
	public function oneToOne_6() {
		$result = array();
		
		$a = new DomDBTestSimpleObject('a');
		$b = new DomDBTestSimpleObject('b');
		$c = new DomDBTestSimpleObject('c');
		
		$a->object = $b;
		$b->object = $c;
		
		$a->link = $c;
		$b->link = $c;
		
		$a->save();	
		
		$result[] = DomDBTester::testValue( 1, $a->id, 'name', 'a');
		$result[] = DomDBTester::testValue( 1, $b->id, 'name', 'b');
		$result[] = DomDBTester::testValue( 1, $c->id, 'name', 'c');
		$result[] = DomDBTester::testValue( 1, $a->id, 'link', $c->id);
		$result[] = DomDBTester::testValue( 1, $b->id, 'link', $c->id);
		$result[] = DomDBTester::testParent( 1, $a->id, 'object', $b->id);
		$result[] = DomDBTester::testParent( 1, $b->id, 'object', $c->id);
		
		$a->delete();
		
		$result[] = DomDBTester::testExistance( 2, $a->id, 'domdbtestsimpleobject');
		$result[] = DomDBTester::testExistance( 2, $b->id, 'domdbtestsimpleobject');
		$result[] = DomDBTester::testExistance( 2, $c->id, 'domdbtestsimpleobject');

		return $result;
	}
	
	public function oneToOne_7() {
		$result = array();
		
		$a = new DomDBTestSimpleObject('a');
		$b = new DomDBTestSimpleObject('b');
		$c = new DomDBTestSimpleObject('c');
		
		$a->save();
		$result[0] = DomDBTester::testValue( 1, $a->id, 'name', 'a');
		
		$b->save();
		$result[1] = DomDBTester::testValue( 1, $b->id, 'name', 'b');
		
		$a->link = $b;
		$a->save();
		$result[2] = DomDBTester::testValue( 1, $a->id, 'link', $b->id);
	
		$a->object = $b;
		$a->save();

		$result[3] = DomDBTester::testParent( 1, $a->id, 'object', $b->id);
		$result[4] = DomDBTester::testValue( 1, $a->id, 'link', $b->id);
		$result[5] = DomDBTester::testValue( 1, $a->id, 'name', 'a');
		$result[6] = DomDBTester::testValue( 1, $b->id, 'name', 'b');
		
		$a->delete();
		
		$result[7] = DomDBTester::testExistance( 2, $a->id, 'domdbtestsimpleobject');
		$result[8] = DomDBTester::testExistance( 2, $b->id, 'domdbtestsimpleobject');
		$result[9] = DomDBTester::testExistance( 2, $c->id, 'domdbtestsimpleobject');

		return $result;
	}
	

	public function complex_1() {
		$result = array();
		
		$a = new DomDBTestSimpleObject('a');
		$b = new DomDBTestSimpleObject('b');
		$c = new DomDBTestSimpleObject('c');
		$d = new DomDBTestSimpleObject('d');
		$e = new DomDBTestSimpleObject('e');
		
		$a->object = $b;
		$b->object = $c;
		$c->object = $d;
		$a->save();	
		
		$result[] = DomDBTester::testValue( 1, $a->id, 'name', 'a');
		$result[] = DomDBTester::testValue( 1, $b->id, 'name', 'b');
		$result[] = DomDBTester::testValue( 1, $c->id, 'name', 'c');
		$result[] = DomDBTester::testValue( 1, $d->id, 'name', 'd');
		
		$result[] = DomDBTester::testParent( 1, $a->id, 'object', $b->id);
		$result[] = DomDBTester::testParent( 1, $b->id, 'object', $c->id);
		$result[] = DomDBTester::testParent( 1, $c->id, 'object', $d->id);
		
		$d->removeParent();
		$result[] = DomDBTester::testParent( 2, $c->id, 'object', $d->id);
		$result[] = DomDBTester::testValue( 1, $c->id, 'object', 0);
		
		$a->object = $e;
		$result[] = DomDBTester::testExistance( 2, $b->id, 'domdbtestsimpleobject');
		$result[] = DomDBTester::testExistance( 2, $c->id, 'domdbtestsimpleobject');
		
		
		$a->save();
		$result[] = DomDBTester::testParent( 1, $a->id, 'object', $e->id);
		
		$a->delete();
		$result[] = DomDBTester::testExistance( 2, $a->id, 'domdbtestsimpleobject');
		$result[] = DomDBTester::testExistance( 2, $e->id, 'domdbtestsimpleobject');
		
		$d->delete();
		$result[] = DomDBTester::testExistance( 2, $d->id, 'domdbtestsimpleobject');
		
		return $result;
	}
	
	
	public function loop_1() {
		//return array( array(false, 0, 'Loop object saving is not supported!') );
		
		$result = array();
		
		$a = new DomDBTestSimpleObject('a');
		$b = new DomDBTestSimpleObject('b');
		
		$a->object = $b;
		$b->object = $a;
		$a->save();	
		
		$result[] = DomDBTester::testValue( 1, $a->id, 'name', 'a');
		$result[] = DomDBTester::testValue( 1, $b->id, 'name', 'b');
		
		$result[] = DomDBTester::testParent( 1, $a->id, 'object', $b->id);
		$result[] = DomDBTester::testParent( 1, $b->id, 'object', $a->id);
		
		$a->delete();
		
		$result[] = DomDBTester::testExistance( 2, $a->id, 'domdbtestsimpleobject');
		$result[] = DomDBTester::testExistance( 2, $b->id, 'domdbtestsimpleobject');

		return $result;
	}
	
	public function loop_2() {
		//return array( array(false, 0, 'Loop object link saving is not supported!') );
		return array();;
		$result = array();
		
		$a = new DomDBTestSimpleObject('a');
		$b = new DomDBTestSimpleObject('b');
		
		$a->link = $b;
		$b->link = $a;
		$a->save();	
		
		$result[] = DomDBTester::testValue( 1, $a->id, 'name', 'a');
		$result[] = DomDBTester::testValue( 1, $b->id, 'name', 'b');

		$a->delete();
		$result[] = DomDBTester::testExistance( 2, $a->id, 'domdbtestsimpleobject');
		$result[] = DomDBTester::testExistance( 1, $b->id, 'domdbtestsimpleobject');
		
		$b->delete();
		$result[] = DomDBTester::testExistance( 2, $b->id, 'domdbtestsimpleobject');

		return $result;
	}
	
	
	public function list_1() {
		$result = array();
		//DomDB::$debug = true;
		$a = new DomDBTestComplexObject('a');
		$b = new DomDBTestComplexObject('b');
		$c = new DomDBTestComplexObject('c');
		$d = new DomDBTestComplexObject('d');
		
		$a->list->push( $b );
		$a->list->push( $c );


		$a->save();	

		$result[0] = DomDBTester::testValue( 1, $a->id, 'name', 'a');
		$result[1] = DomDBTester::testValue( 1, $b->id, 'name', 'b');
		$result[2] = DomDBTester::testValue( 1, $c->id, 'name', 'c');
		$result[3] = DomDBTester::testParent( 1, $a->id, 'list', $b->id);
		$result[4] = DomDBTester::testParent( 1, $a->id, 'list', $c->id);
		
		$a->destroy();
		$b->destroy();
		$c->destroy();
		
		$na = DomDB::load( $a->id );
		
		$result[5] = DomDBTester::testPair( 1, 2, $na->list->count() );
		
		$na->list->push( $d );
		$na->save();
		$result[6] = DomDBTester::testValue( 1, $d->id, 'name', 'd');
		$result[7] = DomDBTester::testParent( 1, $a->id, 'list', $d->id);
		
		
		$nb = $a->list->query('where', 'name = \'b\'', 'limit', 1);
		$nb->name = 'bb';
		$a->save();
		
		$result[11] = DomDBTester::testValue( 1, $nb->id, 'name', 'bb');
		
		$na->list->remove($c);
		$result[] = DomDBTester::testExistance( 2, $c->id, 'domdbtestcomplexobject');
		
		
		$na->delete();
		
		$result[8] = DomDBTester::testExistance( 2, $a->id, 'domdbtestcomplexobject');
		$result[9] = DomDBTester::testExistance( 2, $b->id, 'domdbtestcomplexobject');
		$result[10] = DomDBTester::testExistance( 2, $c->id, 'domdbtestcomplexobject');

		return $result;
	}
	
	public function list_2() {
		$result = array();
		//DomDB::$debug = true;
		$a = new DomDBTestComplexObject('a');
		$b = new DomDBTestComplexObject('b');
		$c = new DomDBTestComplexObject('c');
		$d = new DomDBTestComplexObject('d');
		
		$a->list->push( $b );
		$a->list->push( $c );
		$a->list->push( $d );

		$items  = 0;
		foreach( $a->list as $item ) {
			$result[] = DomDBTester::testPair( 1, get_class($item), 'DomDBTestComplexObject' );
			$items++;
		}
		$result[] = DomDBTester::testPair( 1, $items, 3 );


		$items  = 0;
		$i = $a->list->query();
		while( $item = $i->current() ) {
			$result[] = DomDBTester::testPair( 1, get_class($item), 'DomDBTestComplexObject' );
			$items++;
			$i->next();
		}
		$result[] = DomDBTester::testPair( 1, $items, 3 );

		
		$a->save();	

		$result[] = DomDBTester::testValue( 1, $a->id, 'name', 'a');
		$result[] = DomDBTester::testValue( 1, $b->id, 'name', 'b');
		$result[] = DomDBTester::testValue( 1, $c->id, 'name', 'c');
		$result[] = DomDBTester::testValue( 1, $d->id, 'name', 'd');
		
		$result[] = DomDBTester::testParent( 1, $a->id, 'list', $b->id);
		$result[] = DomDBTester::testParent( 1, $a->id, 'list', $c->id);
		$result[] = DomDBTester::testParent( 1, $a->id, 'list', $d->id);
		
		$a->destroy();
		$b->destroy();
		$c->destroy();
		$d->destroy();
		
		$na = DomDB::load( $a->id );
		
		$items  = 0;
		foreach( $na->list as $item ) {
			$result[] = DomDBTester::testPair( 1, get_class($item), 'DomDBTestComplexObject' );
			$items++;
		}
		$result[] = DomDBTester::testPair( 1, $items, 3 );


		$items  = 0;
		$i = $na->list->query();
		$i->rewind();
		while( $item = $i->current() ) {
			$result[] = DomDBTester::testPair( 1, get_class($item), 'DomDBTestComplexObject' );
			$items++;
			$i->next();
		}
		$result[] = DomDBTester::testPair( 1, $items, 3 );


		$items  = 0;
		foreach( $na->list->query('where', 'name = \'b\'') as $item ) {
			$result[] = DomDBTester::testPair( 1, get_class($item), 'DomDBTestComplexObject' );
			$items++;
		}
		$result[] = DomDBTester::testPair( 1, $items, 1 );


		$it = $na->list->query('where', 'name = \'b\'');
		$result[] = DomDBTester::testPair( 1, $it->count(), 1 );
		
		
		
		$na->delete();
		
		$result[] = DomDBTester::testExistance( 2, $a->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $b->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $c->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $d->id, 'domdbtestcomplexobject');

		return $result;
	}
	
	
	public function linklist_1() {
		$result = array();
		//DomDB::$debug = true;
		$a = new DomDBTestComplexObject('a');
		$b = new DomDBTestComplexObject('b');
		$c = new DomDBTestComplexObject('c');
		$d = new DomDBTestComplexObject('d');
		
		$a->linkList->push( $b );
		$a->linkList->push( $c );


		$a->save();	

		$result[0] = DomDBTester::testValue( 1, $a->id, 'name', 'a');
		$result[1] = DomDBTester::testValue( 1, $b->id, 'name', 'b');
		$result[2] = DomDBTester::testValue( 1, $c->id, 'name', 'c');
		$result[3] = DomDBTester::testLink( 1, $a->id, 'linkList', $b->id);
		$result[4] = DomDBTester::testLink( 1, $a->id, 'linkList', $c->id);
		
		$a->destroy();
		$b->destroy();
		$c->destroy();
		
		$na = DomDB::load( $a->id );
		
		$result[5] = DomDBTester::testPair( 1, 2, $na->linkList->count() );
		
		$na->linkList->push( $d );
		$na->save();
		$result[6] = DomDBTester::testValue( 1, $d->id, 'name', 'd');
		$result[7] = DomDBTester::testLink( 1, $a->id, 'linkList', $d->id);
		
		
		$nb = $a->linkList->query('where', 't.name = \'b\'', 'limit', 1);
		$nb->name = 'bb';
		$a->save();
		
		$result[11] = DomDBTester::testValue( 1, $nb->id, 'name', 'bb');
		
		
		$na->linkList->remove($c);
		$result[3] = DomDBTester::testLink( 2, $a->id, 'linkList', $c->id);
		$result[9] = DomDBTester::testExistance( 1, $c->id, 'domdbtestcomplexobject');
		
		
		$na->delete();
		
		$result[8] = DomDBTester::testExistance( 2, $a->id, 'domdbtestcomplexobject');
		$result[9] = DomDBTester::testExistance( 1, $b->id, 'domdbtestcomplexobject');
		$result[10] = DomDBTester::testExistance( 1, $c->id, 'domdbtestcomplexobject');
		$result[12] = DomDBTester::testExistance( 1, $d->id, 'domdbtestcomplexobject');
		
		$b->delete();
		$c->delete();
		$d->delete();
		
		$result[] = DomDBTester::testExistance( 2, $b->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $c->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $d->id, 'domdbtestcomplexobject');

		return $result;
	}
	
	public function linklist_2() {
		$result = array();
		//DomDB::$debug = true;
		$a = new DomDBTestComplexObject('a');
		$b = new DomDBTestComplexObject('b');
		$c = new DomDBTestComplexObject('c');
		$d = new DomDBTestComplexObject('d');
		
		$a->linkList->push( $b );
		$a->linkList->push( $c );
		$a->linkList->push( $d );

		$items  = 0;
		foreach( $a->linkList as $item ) {
			$result[] = DomDBTester::testPair( 1, get_class($item), 'DomDBTestComplexObject' );
			$items++;
		}
		$result[] = DomDBTester::testPair( 1, $items, 3 );


		$items  = 0;
		$i = $a->linkList->query();
		$i->rewind();
		while( $item = $i->current() ) {
			$result[] = DomDBTester::testPair( 1, get_class($item), 'DomDBTestComplexObject' );
			$items++;
			$i->next();
		}
		$result[] = DomDBTester::testPair( 1, $items, 3 );

		
		$a->save();	

		$result[] = DomDBTester::testValue( 1, $a->id, 'name', 'a');
		$result[] = DomDBTester::testValue( 1, $b->id, 'name', 'b');
		$result[] = DomDBTester::testValue( 1, $c->id, 'name', 'c');
		$result[] = DomDBTester::testValue( 1, $d->id, 'name', 'd');
		
		$result[] = DomDBTester::testLink( 1, $a->id, 'linkList', $b->id);
		$result[] = DomDBTester::testLink( 1, $a->id, 'linkList', $c->id);
		$result[] = DomDBTester::testLink( 1, $a->id, 'linkList', $d->id);
		
		$a->destroy();
		$b->destroy();
		$c->destroy();
		$d->destroy();
		
		$na = DomDB::load( $a->id );
		
		$items  = 0;
		foreach( $na->linkList as $item ) {
			$result[] = DomDBTester::testPair( 1, get_class($item), 'DomDBTestComplexObject' );
			$items++;
		}
		$result[] = DomDBTester::testPair( 1, $items, 3 );


		$items  = 0;
		$i = $na->linkList->query();
		$i->rewind();
		while( $item = $i->current() ) {
			$result[] = DomDBTester::testPair( 1, get_class($item), 'DomDBTestComplexObject' );
			$items++;
			$i->next();
		}
		$result[] = DomDBTester::testPair( 1, $items, 3 );


		$items  = 0;
		foreach( $na->linkList->query('where', 't.name = \'b\'') as $item ) {
			$result[] = DomDBTester::testPair( 1, get_class($item), 'DomDBTestComplexObject' );
			$items++;
		}
		$result[] = DomDBTester::testPair( 1, $items, 1 );


		$it = $na->linkList->query('where', 't.name = \'b\'');
		$result[] = DomDBTester::testPair( 1, $it->count(), 1 );
		
		
		
		$na->delete();
		
		$result[] = DomDBTester::testExistance( 2, $a->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 1, $b->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 1, $c->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 1, $d->id, 'domdbtestcomplexobject');
		
		$b->delete();
		$c->delete();
		$d->delete();
		
		$result[] = DomDBTester::testExistance( 2, $b->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $c->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $d->id, 'domdbtestcomplexobject');

		return $result;
	}
	
	
	public function parentlinklist_1() {
		$result = array();
		//DomDB::$debug = true;
		$a = new DomDBTestLinkList('a');
		$b = new DomDBTestLinkList('b');
		$c = new DomDBTestLinkList('c');
		$d = new DomDBTestLinkList('d');
		
		$a->linkList->push( $b );
		$a->linkList->push( $c );
		$a->save();	
		
		$b->linkList->push( $c );
		$b->save();

		$result[] = DomDBTester::testValue( 1, $a->id, 'name', 'a');
		$result[] = DomDBTester::testValue( 1, $b->id, 'name', 'b');
		$result[] = DomDBTester::testValue( 1, $c->id, 'name', 'c');
		$result[] = DomDBTester::testLink( 1, $a->id, 'linkList', $b->id);
		$result[] = DomDBTester::testLink( 1, $a->id, 'linkList', $c->id);
		$result[] = DomDBTester::testPair( 1, 2, $a->linkList->count() );
		
		
		$result[] = DomDBTester::testPair( 1, 1, $b->parentLinkList->count() );
		$result[] = DomDBTester::testPair( 1, 2, $c->parentLinkList->count() );
		
		$parents = $c->parentLinkList->getArray();
		$result[] = DomDBTester::testPair( 1, 'a', $parents[0]->name );
		$result[] = DomDBTester::testPair( 1, 'b', $parents[1]->name );
	
		$parents = $b->parentLinkList->getArray();
		$result[] = DomDBTester::testPair( 1, 'a', $parents[0]->name );
	
		try {
			$b->parentLinkList->push( $d );
			$result[] = DomDBTester::fail( 'Adding unsaved object to parentList should fail!' );
		} catch( DomDBException $e) {
			if( $e->errno != 2020 ) throw $e;
		}
		
		$d->save();
		$b->parentLinkList->push( $d );
		$b->save();
	
		$parents = $b->parentLinkList->getArray();
		$result[] = DomDBTester::testPair( 1, 'a', $parents[0]->name );
		$result[] = DomDBTester::testPair( 1, 'd', $parents[1]->name );
		$result[] = DomDBTester::testPair( 1, 2, $b->parentLinkList->count() );
		
		$parents = $d->linkList->getArray();
		$result[] = DomDBTester::testPair( 1, 'b', $parents[0]->name );
		$result[] = DomDBTester::testPair( 1, 1, $d->linkList->count() );
		
		
		
		$b->parentLinkList->remove( $d );
		$parents = $b->parentLinkList->getArray();
		$result[] = DomDBTester::testPair( 1, 'a', $parents[0]->name );
		$result[] = DomDBTester::testPair( 1, 1, $b->parentLinkList->count() );
		$result[] = DomDBTester::testPair( 1, 0, $d->linkList->count() );
		
		
		
		$a->delete();
		
		$result[] = DomDBTester::testExistance( 2, $a->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 1, $b->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 1, $c->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 1, $d->id, 'domdbtestcomplexobject');
		
		$b->delete();
		$c->delete();
		$d->delete();
		
		$result[] = DomDBTester::testExistance( 2, $b->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $c->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $d->id, 'domdbtestcomplexobject');

		return $result;
	}
	
	
	public function orderedListTest_1() {
		$result = array();
		//DomDB::$debug = true;
		$a = new DomDBTestComplexObject('a');
		$b = new DomDBTestComplexObject('b');
		$c = new DomDBTestComplexObject('c');
		$d = new DomDBTestComplexObject('d');
		
		$a->orderedList->push( $b );
		$a->orderedList->push( $c );


		$a->save();	

		$result[0] = DomDBTester::testValue( 1, $a->id, 'name', 'a');
		$result[1] = DomDBTester::testValue( 1, $b->id, 'name', 'b');
		$result[2] = DomDBTester::testValue( 1, $c->id, 'name', 'c');
		$result[3] = DomDBTester::testParent( 1, $a->id, 'orderedList', $b->id);
		$result[4] = DomDBTester::testParent( 1, $a->id, 'orderedList', $c->id);
		
		$a->destroy();
		$b->destroy();
		$c->destroy();
		
		$na = DomDB::load( $a->id );
		
		$result[5] = DomDBTester::testPair( 1, 2, $na->orderedList->count() );
		
		$na->orderedList->push( $d );
		$na->save();
		$result[6] = DomDBTester::testValue( 1, $d->id, 'name', 'd');
		$result[7] = DomDBTester::testParent( 1, $a->id, 'orderedList', $d->id);
		
		
		$nb = $a->orderedList->query('where', 'name = \'b\'', 'limit', 1);
		$nb->name = 'bb';
		$a->save();
		
		$result[11] = DomDBTester::testValue( 1, $nb->id, 'name', 'bb');
		
		$na->orderedList->remove($c);
		$result[] = DomDBTester::testExistance( 2, $c->id, 'domdbtestcomplexobject');
		
		
		$na->delete();
		
		$result[8] = DomDBTester::testExistance( 2, $a->id, 'domdbtestcomplexobject');
		$result[9] = DomDBTester::testExistance( 2, $b->id, 'domdbtestcomplexobject');
		$result[10] = DomDBTester::testExistance( 2, $c->id, 'domdbtestcomplexobject');

		return $result;
	}
	
	public function orderedListTest_2() {
		$result = array();
		//DomDB::$debug = true;
		$a = new DomDBTestComplexObject('a');
		$b = new DomDBTestComplexObject('b');
		$c = new DomDBTestComplexObject('c');
		$d = new DomDBTestComplexObject('d');
		
		$a->orderedList->push( $b );
		$a->orderedList->push( $c );
		$a->orderedList->push( $d );

		$items  = 0;
		foreach( $a->orderedList as $item ) {
			$result[] = DomDBTester::testPair( 1, get_class($item), 'DomDBTestComplexObject' );
			$items++;
		}
		$result[] = DomDBTester::testPair( 1, $items, 3 );


		$items  = 0;
		$i = $a->orderedList->query();
		while( $item = $i->current() ) {
			$result[] = DomDBTester::testPair( 1, get_class($item), 'DomDBTestComplexObject' );
			$items++;
			$i->next();
		}
		$result[] = DomDBTester::testPair( 1, $items, 3 );

		
		$a->save();	

		$result[] = DomDBTester::testValue( 1, $a->id, 'name', 'a');
		$result[] = DomDBTester::testValue( 1, $b->id, 'name', 'b');
		$result[] = DomDBTester::testValue( 1, $c->id, 'name', 'c');
		$result[] = DomDBTester::testValue( 1, $d->id, 'name', 'd');
		
		$result[] = DomDBTester::testParent( 1, $a->id, 'orderedList', $b->id);
		$result[] = DomDBTester::testParent( 1, $a->id, 'orderedList', $c->id);
		$result[] = DomDBTester::testParent( 1, $a->id, 'orderedList', $d->id);
		
		$a->destroy();
		$b->destroy();
		$c->destroy();
		$d->destroy();
		
		$na = DomDB::load( $a->id );
		
		$items  = 0;
		foreach( $na->orderedList as $item ) {
			$result[] = DomDBTester::testPair( 1, get_class($item), 'DomDBTestComplexObject' );
			$items++;
		}
		$result[] = DomDBTester::testPair( 1, $items, 3 );


		$items  = 0;
		$i = $na->orderedList->query();
		$i->rewind();
		while( $item = $i->current() ) {
			$result[] = DomDBTester::testPair( 1, get_class($item), 'DomDBTestComplexObject' );
			$items++;
			$i->next();
		}
		$result[] = DomDBTester::testPair( 1, $items, 3 );


		$items  = 0;
		foreach( $na->orderedList->query('where', 'name = \'b\'') as $item ) {
			$result[] = DomDBTester::testPair( 1, get_class($item), 'DomDBTestComplexObject' );
			$items++;
		}
		$result[] = DomDBTester::testPair( 1, $items, 1 );


		$it = $na->orderedList->query('where', 'name = \'b\'');
		$result[] = DomDBTester::testPair( 1, $it->count(), 1 );
		
		
		
		$na->delete();
		
		$result[] = DomDBTester::testExistance( 2, $a->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $b->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $c->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $d->id, 'domdbtestcomplexobject');

		return $result;
	}
	
	public function orderedListTest_3() {
		$result = array();
		//DomDB::$debug = true;
		$a = new DomDBTestComplexObject('a');
		$b = new DomDBTestComplexObject('b');
		$c = new DomDBTestComplexObject('c');
		$d = new DomDBTestComplexObject('d');
		
		$a->orderedList->push( $b );
		$a->orderedList->push( $c );
		$a->orderedList->push( $d );

		$a->save();	

		$list = $a->orderedList->getArray();
		$result[] = DomDBTester::testPair( 1, $list[0]->name, 'b' );
		$result[] = DomDBTester::testPair( 1, $list[1]->name, 'c' );
		$result[] = DomDBTester::testPair( 1, $list[2]->name, 'd' );


		$a->orderedList->moveUp($c);
		$list = $a->orderedList->getArray();
		$result[] = DomDBTester::testPair( 1, $list[0]->name, 'c' );
		$result[] = DomDBTester::testPair( 1, $list[1]->name, 'b' );
		$result[] = DomDBTester::testPair( 1, $list[2]->name, 'd' );


		$a->orderedList->moveUp($c);
		$list = $a->orderedList->getArray();
		$result[] = DomDBTester::testPair( 1, $list[0]->name, 'c' );
		$result[] = DomDBTester::testPair( 1, $list[1]->name, 'b' );
		$result[] = DomDBTester::testPair( 1, $list[2]->name, 'd' );
		
		$a->orderedList->moveDown($b);
		$list = $a->orderedList->getArray();
		$result[] = DomDBTester::testPair( 1, $list[0]->name, 'c' );
		$result[] = DomDBTester::testPair( 1, $list[1]->name, 'd' );
		$result[] = DomDBTester::testPair( 1, $list[2]->name, 'b' );

		$a->orderedList->moveDown($b);
		$list = $a->orderedList->getArray();
		$result[] = DomDBTester::testPair( 1, $list[0]->name, 'c' );
		$result[] = DomDBTester::testPair( 1, $list[1]->name, 'd' );
		$result[] = DomDBTester::testPair( 1, $list[2]->name, 'b' );
		
		$a->orderedList->moveFirst($b);
		$list = $a->orderedList->getArray();
		$result[] = DomDBTester::testPair( 1, $list[0]->name, 'b' );
		$result[] = DomDBTester::testPair( 1, $list[1]->name, 'c' );
		$result[] = DomDBTester::testPair( 1, $list[2]->name, 'd' );
		
		$a->orderedList->moveLast($b);
		$list = $a->orderedList->getArray();
		$result[] = DomDBTester::testPair( 1, $list[0]->name, 'c' );
		$result[] = DomDBTester::testPair( 1, $list[1]->name, 'd' );
		$result[] = DomDBTester::testPair( 1, $list[2]->name, 'b' );
		
		$a->orderedList->swap( $b, $c);
		$list = $a->orderedList->getArray();
		$result[] = DomDBTester::testPair( 1, $list[0]->name, 'b' );
		$result[] = DomDBTester::testPair( 1, $list[1]->name, 'd' );
		$result[] = DomDBTester::testPair( 1, $list[2]->name, 'c' );

		
		$next = $a->orderedList->getNext( $d );
		$result[] = DomDBTester::testPair( 1, $next->name, 'c' );
		
		$prev = $a->orderedList->getPrev( $d );
		$result[] = DomDBTester::testPair( 1, $prev->name, 'b' );
		
		$a->delete();
		
		$result[] = DomDBTester::testExistance( 2, $a->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $b->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $c->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $d->id, 'domdbtestcomplexobject');

		return $result;
	}
	
	
	public function orderedlinklistTest_1() {
		$result = array();
		//DomDB::$debug = true;
		$a = new DomDBTestComplexObject('a');
		$b = new DomDBTestComplexObject('b');
		$c = new DomDBTestComplexObject('c');
		$d = new DomDBTestComplexObject('d');
		
		$a->orderedLinkList->push( $b );
		$a->orderedLinkList->push( $c );


		$a->save();	

		$result[0] = DomDBTester::testValue( 1, $a->id, 'name', 'a');
		$result[1] = DomDBTester::testValue( 1, $b->id, 'name', 'b');
		$result[2] = DomDBTester::testValue( 1, $c->id, 'name', 'c');
		$result[3] = DomDBTester::testLink( 1, $a->id, 'orderedLinkList', $b->id);
		$result[4] = DomDBTester::testLink( 1, $a->id, 'orderedLinkList', $c->id);
		
		$a->destroy();
		$b->destroy();
		$c->destroy();
		
		$na = DomDB::load( $a->id );
		
		$result[5] = DomDBTester::testPair( 1, 2, $na->orderedLinkList->count() );
		
		$na->orderedLinkList->push( $d );
		$na->save();
		$result[6] = DomDBTester::testValue( 1, $d->id, 'name', 'd');
		$result[7] = DomDBTester::testLink( 1, $a->id, 'orderedLinkList', $d->id);
		
		
		$nb = $a->orderedLinkList->query('where', 't.name = \'b\'', 'limit', 1);
		$nb->name = 'bb';
		$a->save();
		
		$result[11] = DomDBTester::testValue( 1, $nb->id, 'name', 'bb');
		
		
		$na->orderedLinkList->remove($c);
		$result[3] = DomDBTester::testLink( 2, $a->id, 'orderedLinkList', $c->id);
		$result[9] = DomDBTester::testExistance( 1, $c->id, 'domdbtestcomplexobject');
		
		
		$na->delete();
		
		$result[8] = DomDBTester::testExistance( 2, $a->id, 'domdbtestcomplexobject');
		$result[9] = DomDBTester::testExistance( 1, $b->id, 'domdbtestcomplexobject');
		$result[10] = DomDBTester::testExistance( 1, $c->id, 'domdbtestcomplexobject');
		$result[12] = DomDBTester::testExistance( 1, $d->id, 'domdbtestcomplexobject');
		
		$b->delete();
		$c->delete();
		$d->delete();
		
		$result[] = DomDBTester::testExistance( 2, $b->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $c->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $d->id, 'domdbtestcomplexobject');

		return $result;
	}
	
	public function orderedlinklistTest_2() {
		$result = array();
		//DomDB::$debug = true;
		$a = new DomDBTestComplexObject('a');
		$b = new DomDBTestComplexObject('b');
		$c = new DomDBTestComplexObject('c');
		$d = new DomDBTestComplexObject('d');
		
		$a->orderedLinkList->push( $b );
		$a->orderedLinkList->push( $c );
		$a->orderedLinkList->push( $d );

		$items  = 0;
		foreach( $a->orderedLinkList as $item ) {
			$result[] = DomDBTester::testPair( 1, get_class($item), 'DomDBTestComplexObject' );
			$items++;
		}
		$result[] = DomDBTester::testPair( 1, $items, 3 );


		$items  = 0;
		$i = $a->orderedLinkList->query();
		$i->rewind();
		while( $item = $i->current() ) {
			$result[] = DomDBTester::testPair( 1, get_class($item), 'DomDBTestComplexObject' );
			$items++;
			$i->next();
		}
		$result[] = DomDBTester::testPair( 1, $items, 3 );

		
		$a->save();	

		$result[] = DomDBTester::testValue( 1, $a->id, 'name', 'a');
		$result[] = DomDBTester::testValue( 1, $b->id, 'name', 'b');
		$result[] = DomDBTester::testValue( 1, $c->id, 'name', 'c');
		$result[] = DomDBTester::testValue( 1, $d->id, 'name', 'd');
		
		$result[] = DomDBTester::testLink( 1, $a->id, 'orderedLinkList', $b->id);
		$result[] = DomDBTester::testLink( 1, $a->id, 'orderedLinkList', $c->id);
		$result[] = DomDBTester::testLink( 1, $a->id, 'orderedLinkList', $d->id);
		
		$a->destroy();
		$b->destroy();
		$c->destroy();
		$d->destroy();
		
		$na = DomDB::load( $a->id );
		
		$items  = 0;
		foreach( $na->orderedLinkList as $item ) {
			$result[] = DomDBTester::testPair( 1, get_class($item), 'DomDBTestComplexObject' );
			$items++;
		}
		$result[] = DomDBTester::testPair( 1, $items, 3 );


		$items  = 0;
		$i = $na->orderedLinkList->query();
		$i->rewind();
		while( $item = $i->current() ) {
			$result[] = DomDBTester::testPair( 1, get_class($item), 'DomDBTestComplexObject' );
			$items++;
			$i->next();
		}
		$result[] = DomDBTester::testPair( 1, $items, 3 );


		$items  = 0;
		foreach( $na->orderedLinkList->query('where', 't.name = \'b\'') as $item ) {
			$result[] = DomDBTester::testPair( 1, get_class($item), 'DomDBTestComplexObject' );
			$items++;
			$i->next();
		}
		$result[] = DomDBTester::testPair( 1, $items, 1 );


		$it = $na->orderedLinkList->query('where', 't.name = \'b\'');
		$result[] = DomDBTester::testPair( 1, $it->count(), 1 );
		
		
		
		$na->delete();
		
		$result[] = DomDBTester::testExistance( 2, $a->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 1, $b->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 1, $c->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 1, $d->id, 'domdbtestcomplexobject');
		
		$b->delete();
		$c->delete();
		$d->delete();
		
		$result[] = DomDBTester::testExistance( 2, $b->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $c->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $d->id, 'domdbtestcomplexobject');

		return $result;
	}
	
	public function orderedListTestTest_3() {
		$result = array();
		//DomDB::$debug = true;
		$a = new DomDBTestComplexObject('a');
		$b = new DomDBTestComplexObject('b');
		$c = new DomDBTestComplexObject('c');
		$d = new DomDBTestComplexObject('d');
		
		$a->orderedLinkList->push( $b );
		$a->orderedLinkList->push( $c );
		$a->orderedLinkList->push( $d );

		$a->save();	

		$list = $a->orderedLinkList->getArray();
		$result[] = DomDBTester::testPair( 1, $list[0]->name, 'b' );
		$result[] = DomDBTester::testPair( 1, $list[1]->name, 'c' );
		$result[] = DomDBTester::testPair( 1, $list[2]->name, 'd' );


		$a->orderedLinkList->moveUp($c);
		$list = $a->orderedLinkList->getArray();
		$result[] = DomDBTester::testPair( 1, $list[0]->name, 'c' );
		$result[] = DomDBTester::testPair( 1, $list[1]->name, 'b' );
		$result[] = DomDBTester::testPair( 1, $list[2]->name, 'd' );


		$a->orderedLinkList->moveUp($c);
		$list = $a->orderedLinkList->getArray();
		$result[] = DomDBTester::testPair( 1, $list[0]->name, 'c' );
		$result[] = DomDBTester::testPair( 1, $list[1]->name, 'b' );
		$result[] = DomDBTester::testPair( 1, $list[2]->name, 'd' );
		
		$a->orderedLinkList->moveDown($b);
		$list = $a->orderedLinkList->getArray();
		$result[] = DomDBTester::testPair( 1, $list[0]->name, 'c' );
		$result[] = DomDBTester::testPair( 1, $list[1]->name, 'd' );
		$result[] = DomDBTester::testPair( 1, $list[2]->name, 'b' );

		$a->orderedLinkList->moveDown($b);
		$list = $a->orderedLinkList->getArray();
		$result[] = DomDBTester::testPair( 1, $list[0]->name, 'c' );
		$result[] = DomDBTester::testPair( 1, $list[1]->name, 'd' );
		$result[] = DomDBTester::testPair( 1, $list[2]->name, 'b' );
		
		$a->orderedLinkList->moveFirst($b);
		$list = $a->orderedLinkList->getArray();
		$result[] = DomDBTester::testPair( 1, $list[0]->name, 'b' );
		$result[] = DomDBTester::testPair( 1, $list[1]->name, 'c' );
		$result[] = DomDBTester::testPair( 1, $list[2]->name, 'd' );
		
		$a->orderedLinkList->moveLast($b);
		$list = $a->orderedLinkList->getArray();
		$result[] = DomDBTester::testPair( 1, $list[0]->name, 'c' );
		$result[] = DomDBTester::testPair( 1, $list[1]->name, 'd' );
		$result[] = DomDBTester::testPair( 1, $list[2]->name, 'b' );
		
		$a->orderedLinkList->swap( $b, $c);
		$list = $a->orderedLinkList->getArray();
		$result[] = DomDBTester::testPair( 1, $list[0]->name, 'b' );
		$result[] = DomDBTester::testPair( 1, $list[1]->name, 'd' );
		$result[] = DomDBTester::testPair( 1, $list[2]->name, 'c' );

		
		//$next = $a->orderedLinkList->getNext( $d );
		//$result[] = DomDBTester::testPair( 1, $next->name, 'c' );
		
		//$prev = $a->orderedLinkList->getPrev( $d );
		//$result[] = DomDBTester::testPair( 1, $prev->name, 'b' );
		
		$a->delete();
		$b->delete();
		$c->delete();
		$d->delete();
		
		$result[] = DomDBTester::testExistance( 2, $a->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $b->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $c->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $d->id, 'domdbtestcomplexobject');

		return $result;
	}
	
	
	public function orderedMultiListTest_1() {
		$result = array();
		//DomDB::$debug = true;
		$a = new DomDBTestComplexObject('a');
		$b = new DomDBTestComplexObject('b');
		$c = new DomDBTestComplexObject('c');
		$d = new DomDBTestComplexObject('d');
		
		$a->orderedMultiList->push( $b );
		$a->orderedMultiList->push( $c );

		$a->save();	

		$result[] = DomDBTester::testValue( 1, $a->id, 'name', 'a');
		$result[] = DomDBTester::testValue( 1, $b->id, 'name', 'b');
		$result[] = DomDBTester::testValue( 1, $c->id, 'name', 'c');
		$result[] = DomDBTester::testParent( 1, $a->id, 'orderedMultiList', $b->id);
		$result[] = DomDBTester::testParent( 1, $a->id, 'orderedMultiList', $c->id);

		$a->destroy();
		$b->destroy();
		$c->destroy();
		
		$na = DomDB::load( $a->id );
		
		$result[] = DomDBTester::testPair( 1, 2, $na->orderedMultiList->count() );
		
		$na->orderedMultiList->push( $d );
		$na->save();
		$result[] = DomDBTester::testValue( 1, $d->id, 'name', 'd');
		$result[] = DomDBTester::testParent( 1, $a->id, 'orderedMultiList', $d->id);
		
		
		$elements = $a->orderedMultiList->getQuery();

		$nb = $elements[0];
		$nb->name = 'bb';
		$a->save();
		
		$result[] = DomDBTester::testValue( 1, $nb->id, 'name', 'bb');
		
		
		$na->orderedMultiList->remove($c);
		$result[] = DomDBTester::testExistance( 2, $c->id, 'domdbtestcomplexobject');
		
		
		$na->delete();
		
		$result[] = DomDBTester::testExistance( 2, $a->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $b->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $c->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $d->id, 'domdbtestcomplexobject');


		return $result;
	}
	
	public function orderedMultiListTest_2() {
		$result = array();
		//DomDB::$debug = true;
		$a = new DomDBTestComplexObject('a');
		$b = new DomDBTestComplexObject('b');
		$c = new DomDBTestComplexObject('c');
		$d = new DomDBTestComplexObject('d');
		
		$a->orderedMultiList->push( $b );
		$a->orderedMultiList->push( $c );
		$a->orderedMultiList->push( $d );

		$items  = 0;
		foreach( $a->orderedMultiList as $item ) {
			$result[] = DomDBTester::testPair( 1, get_class($item), 'DomDBTestComplexObject' );
			$items++;
		}
		$result[] = DomDBTester::testPair( 1, $items, 3 );


		$items  = 0;
		$i = $a->orderedMultiList->query();
		while( $item = $i->current() ) {
			$result[] = DomDBTester::testPair( 1, get_class($item), 'DomDBTestComplexObject' );
			$items++;
			$i->next();
		}
		$result[] = DomDBTester::testPair( 1, $items, 3 );

		
		$a->save();	

		$result[] = DomDBTester::testValue( 1, $a->id, 'name', 'a');
		$result[] = DomDBTester::testValue( 1, $b->id, 'name', 'b');
		$result[] = DomDBTester::testValue( 1, $c->id, 'name', 'c');
		$result[] = DomDBTester::testValue( 1, $d->id, 'name', 'd');
		
		$result[] = DomDBTester::testParent( 1, $a->id, 'orderedMultiList', $b->id);
		$result[] = DomDBTester::testParent( 1, $a->id, 'orderedMultiList', $c->id);
		$result[] = DomDBTester::testParent( 1, $a->id, 'orderedMultiList', $d->id);
		
		$a->destroy();
		$b->destroy();
		$c->destroy();
		$d->destroy();
		
		$na = DomDB::load( $a->id );
		
		$items  = 0;
		foreach( $na->orderedMultiList as $item ) {
			$result[] = DomDBTester::testPair( 1, get_class($item), 'DomDBTestComplexObject' );
			$items++;
		}
		$result[] = DomDBTester::testPair( 1, $items, 3 );


		$items  = 0;
		$i = $na->orderedMultiList->query();
		while( $item = $i->current() ) {
			$result[] = DomDBTester::testPair( 1, get_class($item), 'DomDBTestComplexObject' );
			$items++;
			$i->next();
		}
		$result[] = DomDBTester::testPair( 1, $items, 3 );
		
		
		$na->delete();
		
		$result[] = DomDBTester::testExistance( 2, $a->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $b->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $c->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $d->id, 'domdbtestcomplexobject');

		return $result;
	}
	
	public function orderedMultiListTest_3() {
		$result = array();
		//DomDB::$debug = true;
		$a = new DomDBTestComplexObject('a');
		$b = new DomDBTestComplexObject('b');
		$c = new DomDBTestComplexObject('c');
		$d = new DomDBTestComplexObject('d');
		
		$a->orderedMultiList->push( $b );
		$a->orderedMultiList->push( $c );
		$a->orderedMultiList->push( $d );

		$a->save();	

		$list = $a->orderedMultiList->getArray();
		$result[] = DomDBTester::testPair( 1, $list[0]->name, 'b' );
		$result[] = DomDBTester::testPair( 1, $list[1]->name, 'c' );
		$result[] = DomDBTester::testPair( 1, $list[2]->name, 'd' );


		$a->orderedMultiList->moveUp($c);
		$list = $a->orderedMultiList->getArray();
		$result[] = DomDBTester::testPair( 1, $list[0]->name, 'c' );
		$result[] = DomDBTester::testPair( 1, $list[1]->name, 'b' );
		$result[] = DomDBTester::testPair( 1, $list[2]->name, 'd' );


		$a->orderedMultiList->moveUp($c);
		$list = $a->orderedMultiList->getArray();
		$result[] = DomDBTester::testPair( 1, $list[0]->name, 'c' );
		$result[] = DomDBTester::testPair( 1, $list[1]->name, 'b' );
		$result[] = DomDBTester::testPair( 1, $list[2]->name, 'd' );
		
		$a->orderedMultiList->moveDown($b);
		$list = $a->orderedMultiList->getArray();
		$result[] = DomDBTester::testPair( 1, $list[0]->name, 'c' );
		$result[] = DomDBTester::testPair( 1, $list[1]->name, 'd' );
		$result[] = DomDBTester::testPair( 1, $list[2]->name, 'b' );

		$a->orderedMultiList->moveDown($b);
		$list = $a->orderedMultiList->getArray();
		$result[] = DomDBTester::testPair( 1, $list[0]->name, 'c' );
		$result[] = DomDBTester::testPair( 1, $list[1]->name, 'd' );
		$result[] = DomDBTester::testPair( 1, $list[2]->name, 'b' );
		
		$a->orderedMultiList->moveFirst($b);
		$list = $a->orderedMultiList->getArray();
		$result[] = DomDBTester::testPair( 1, $list[0]->name, 'b' );
		$result[] = DomDBTester::testPair( 1, $list[1]->name, 'c' );
		$result[] = DomDBTester::testPair( 1, $list[2]->name, 'd' );
		
		$a->orderedMultiList->moveLast($b);
		$list = $a->orderedMultiList->getArray();
		$result[] = DomDBTester::testPair( 1, $list[0]->name, 'c' );
		$result[] = DomDBTester::testPair( 1, $list[1]->name, 'd' );
		$result[] = DomDBTester::testPair( 1, $list[2]->name, 'b' );
		
		$a->orderedMultiList->swap( $b, $c);
		$list = $a->orderedMultiList->getArray();
		$result[] = DomDBTester::testPair( 1, $list[0]->name, 'b' );
		$result[] = DomDBTester::testPair( 1, $list[1]->name, 'd' );
		$result[] = DomDBTester::testPair( 1, $list[2]->name, 'c' );

		
		//$next = $a->orderedMultiList->getNext( $d );
		//$result[] = DomDBTester::testPair( 1, $next->name, 'c' );
		
		//$prev = $a->orderedMultiList->getPrev( $d );
		//$result[] = DomDBTester::testPair( 1, $prev->name, 'b' );
		
		$a->delete();
		
		$result[] = DomDBTester::testExistance( 2, $a->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $b->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $c->id, 'domdbtestcomplexobject');
		$result[] = DomDBTester::testExistance( 2, $d->id, 'domdbtestcomplexobject');

		return $result;
	}
	
	/*
	public function keyLinkList_1() {
		$result = array();
		
		$a = new DomDBTestKeyListObject('a');
		$b = new DomDBTestKeyListObject('b');
		$c = new DomDBTestKeyListObject('c');
		
		$a->keyLinkList->push('one', $b );
		$a->keyLinkList->push('two', $c );
		$a->keyLinkList->push('three', $b );

		$a->save();	

		$result[0] = DomDBTester::testValue( 1, $a->id, 'name', 'a');
		$result[1] = DomDBTester::testValue( 1, $b->id, 'name', 'b');
		$result[2] = DomDBTester::testValue( 1, $c->id, 'name', 'c');
		
		// testing link relationship
		$result[3] = DomDBTester::testParent( 2, $a->id, 'object', $b->id);
		$result[4] = DomDBTester::testParent( 2, $b->id, 'object', $c->id);
		
		// testing count
		$result[5] = DomDBTester::testPair(1, 3, $a->keyLinkList->count());
		
		// testing loading already existing objects
		$sample = $a->keyLinkList->getQuery();
		$result[10] = DomDBTester::testPair(1, isset($sample['one']), true);
		$result[11] = DomDBTester::testPair(1, isset($sample['two']), true);
		$result[12] = DomDBTester::testPair(1, isset($sample['three']), true);
		$result[13] = DomDBTester::testPair(1, $sample['one']->id, $b->id);
		$result[14] = DomDBTester::testPair(1, $sample['two']->id, $c->id);
		$result[15] = DomDBTester::testPair(1, $sample['three']->id, $b->id);
		
		$b->destroy();
		$c->destroy();
		
		// testing loading new objects
		$sample = $a->keyLinkList->getQuery();
		$result[21] = DomDBTester::testPair(1, isset($sample['one']), true);
		$result[22] = DomDBTester::testPair(1, isset($sample['two']), true);
		$result[23] = DomDBTester::testPair(1, isset($sample['three']), true);
		$result[24] = DomDBTester::testPair(1, $sample['one']->id, $b->id);
		$result[25] = DomDBTester::testPair(1, $sample['two']->id, $c->id);
		$result[26] = DomDBTester::testPair(1, $sample['three']->id, $b->id);
		
		// testing WHERE
		$sample = $a->keyLinkList->getQuery('where','t3.key = \'two\'');
		$result[31] = DomDBTester::testPair(1, count($sample), 1);
		$result[32] = DomDBTester::testPair(1, isset($sample['one']), false);
		$result[33] = DomDBTester::testPair(1, isset($sample['two']), true);
		$result[34] = DomDBTester::testPair(1, isset($sample['three']), false);
		$result[35] = DomDBTester::testPair(2, $sample['one']->id, $b->id);
		$result[36] = DomDBTester::testPair(1, $sample['two']->id, $c->id);
		$result[37] = DomDBTester::testPair(2, $sample['three']->id, $b->id);
		
		// testing removing
		$a->keyLinkList->remove('three');

		$sample = $a->keyLinkList->getQuery();

		$result[21] = DomDBTester::testPair(1, isset($sample['one']), true);
		$result[22] = DomDBTester::testPair(1, isset($sample['two']), true);
		$result[23] = DomDBTester::testPair(1, isset($sample['three']), false);
		$result[24] = DomDBTester::testPair(1, $sample['one']->id, $b->id);
		$result[25] = DomDBTester::testPair(1, $sample['two']->id, $c->id);
		$result[26] = DomDBTester::testPair(2, $sample['three']->id, $b->id);
		
		
		$a->delete();
		
		$result[50] = DomDBTester::testExistance( 2, $a->id, 'DomDBTestKeyListObject');
		$result[51] = DomDBTester::testExistance( 1, $b->id, 'DomDBTestKeyListObject');
		$result[52] = DomDBTester::testExistance( 1, $c->id, 'DomDBTestKeyListObject');
		
		$b->delete();
		$result[53] = DomDBTester::testExistance( 2, $b->id, 'DomDBTestKeyListObject');
		$c->delete();
		$result[54] = DomDBTester::testExistance( 2, $c->id, 'DomDBTestKeyListObject');

		return $result;
	
	}
	*/
	public function changeTest_1() {

		$result = array();
		
		$a = new DomDBTestSimpleObject('a');
		$b = new DomDBTestSimpleObject('b');
		$c = new DomDBTestSimpleObject('c');

		$a->object = $b;
		$a->save();	
		$c->save();
		
		$a->object = $c;
		$result[] = DomDBTester::testExistance( 2, $b->id, 'domdbtestsimpleobject');
		
		$a->save();
		$result[] = DomDBTester::testParent( 1, $a->id, 'object', $c->id);
		
		$prevQueries = count(DomSql::$monitorData);

		$a->save();
		$result[] = DomDBTester::testPair( 1, $prevQueries, count(DomSql::$monitorData) );
		$result[] = DomDBTester::testParent( 1, $a->id, 'object', $c->id);


		$a->save();
		$result[] = DomDBTester::testPair( 1, $prevQueries, count(DomSql::$monitorData) );
		$result[] = DomDBTester::testParent( 1, $a->id, 'object', $c->id);

		$a->delete();
		$result[] = DomDBTester::testExistance( 2, $a->id, 'domdbtestsimpleobject');
		$result[] = DomDBTester::testExistance( 2, $b->id, 'domdbtestsimpleobject');

		return $result;
	}
	
	public function domFileMapTest_1() {
		$result = array();
		
		$rootFile = 'DomDB_DomFileMap_Test_1_testFileöäüõ.txt';
		$notAllowedFile = 'DomDB_DomFileMap_Test_1_testFileöäüõ.KGLD';
		$sampleFile = 'DomDB_DomFileMap_Test_1_testFile.txt';
		$sampleSecFile = 'DomDB_DomFileMap_Test_1_testFile_sec.txt';
		$sampleRenameFile = 'DomDB_DomFileMap_Test_1_testFile_secRENAME';
		$rootPath = 'C:/SERVER/TESTING/testDir/aa/';
		$rootSecPath = 'C:/SERVER/TESTING/testDir/bb/';
		$secUrl = 'http://localhost/TESTING/testDir/';
	
	
		$h = fopen($rootPath.'../'.$rootFile, 'w+');
		fwrite($h, 'Some sample content');
		fclose($h);
		
		$h = fopen($rootPath.'../'.$notAllowedFile, 'w+');
		fwrite($h, 'Some sample content');
		fclose($h);
	
		$map = new DomFileMap();
		$map->setTypes( array('txt') );
		$map->setPaths( array('main_path'=>$rootPath, 'main_url'=>false, 'sec_path'=>$rootSecPath, 'sec_url'=>$secUrl) );
		$map->setMaxFileSize( 'main', 1024 );
		
		// ------------------------------------------------------------
		// ADD FILE TESTS
		// ------------------------------------------------------------
		
		// test if invalid dir can be given file can be overwritten
		$result[] = DomDBTester::testPair( 1, $map->addFile('main', $rootPath.'../'.$rootFile, 'haha/../hehe/' ), false );
		$result[] = DomDBTester::testPair( 1, $map->getErrorNr(), 19);
		$map->clearError();
		
		// test file doesnt exist when adding
		$result[] = DomDBTester::testPair( 1, $map->addFile('main', $rootPath.'../'.$rootFile.'.FKLD' ), false );
		$result[] = DomDBTester::testPair( 1, $map->getErrorNr(), 12);
		$map->clearError();
		
		// test file extension not allowed
		$result[] = DomDBTester::testPair( 1, $map->addFile('main', $rootPath.'../'.$notAllowedFile ), false );
		$result[] = DomDBTester::testPair( 1, $map->getErrorNr(), 14);
		$map->clearError();
		
		// file too big?
		$map->setMaxFileSize( 'main', 1 );
		$result[] = DomDBTester::testPair( 1, $map->addFile('main', $rootPath.'../'.$rootFile ), false );
		$result[] = DomDBTester::testPair( 1, $map->getErrorNr(), 11);
		$map->clearError();
		$map->setMaxFileSize( 'main', 1024 );
		
		// adding new file
		$result[] = DomDBTester::testPair( 1, $map->addFile('main', $rootPath.'../'.$rootFile ), true );
		$result[] = DomDBTester::testPair( 1, $map->getError(), '');
		
		// test if existing file can be overwritten
		$result[] = DomDBTester::testPair( 1, $map->addFile('main', $rootPath.'../'.$rootFile ), false );
		$result[] = DomDBTester::testPair( 1, $map->getErrorNr(), 13);
		$map->clearError();
		
		$result[] = DomDBTester::testPair( 1, is_file($rootPath.$sampleFile), true );
		$result[] = DomDBTester::testPair( 1, $map->getError(), '');
		
		// ------------------------------------------------------------
		// COPY TESTS
		// ------------------------------------------------------------
		
		// try coping non existing file
		$result[] = DomDBTester::testPair( 1, $map->copy('sec', 'sec' ), false );
		$result[] = DomDBTester::testPair( 1, $map->getErrorNr(), 12);
		$map->clearError();
		
		// new file already exists, cant overwrite!
		$result[] = DomDBTester::testPair( 1, $map->copy('main', 'main' ), false );
		$result[] = DomDBTester::testPair( 1, $map->getErrorNr(), 13);
		$map->clearError();
		
		// copy file
		$result[] = DomDBTester::testPair( 1, $map->copy('main', 'sec' ), true );
		$result[] = DomDBTester::testPair( 1, $map->getError(), '');
		
		// check status
		$result[] = DomDBTester::testPair( 1, is_file($rootSecPath.$sampleSecFile), true );
		$result[] = DomDBTester::testPair( 1, $map->getError(), '');
		
		// ------------------------------------------------------------
		// RENAME TESTS
		// ------------------------------------------------------------
		
		$result[] = DomDBTester::testPair( 1, $map->renameName('main', $sampleRenameFile ), true );
		$result[] = DomDBTester::testPair( 1, $map->getPath('main'), $rootPath . $sampleRenameFile.'.txt');
		$result[] = DomDBTester::testPair( 1, $map->getError(), '');
		
		$result[] = DomDBTester::testPair( 1, $map->renameRelativePath('main', 'rela/' ), true );
		$result[] = DomDBTester::testPair( 1, $map->getPath('main'), $rootPath . 'rela/' . $sampleRenameFile.'.txt');
		$result[] = DomDBTester::testPair( 1, $map->getError(), '');
		
		// ------------------------------------------------------------
		// UNLINK TESTS
		// ------------------------------------------------------------
		
		$map->unlink('main');
		$map->unlink('sec');

		$result[] = DomDBTester::testPair( 1, is_file($rootPath.$sampleFile), false );
		$result[] = DomDBTester::testPair( 1, $map->getError(), '');
		$result[] = DomDBTester::testPair( 1, is_file($rootSecPath.$sampleSecFile), false );
		$result[] = DomDBTester::testPair( 1, $map->getError(), '');
	
		// ------------------------------------------------------------
		// Clear test items
		// ------------------------------------------------------------
		rmdir($rootPath.'rela/');
		rmdir($rootPath);
		rmdir($rootSecPath);
		unlink($rootPath.'../'.$rootFile);
		unlink($rootPath.'../'.$notAllowedFile);
	
		return $result;
	}
	
}
?>